package com.ly.video.api.config.controller;

import com.ly.video.api.config.entity.DialogEntity;
import com.ly.video.api.config.impl.ConfigServiceImpl;
import com.ly.video.common.util.JsonResult;
import com.ly.video.common.util.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "config")
@CrossOrigin(origins = "*")
public class ConfigController {

    @Autowired
    private ConfigServiceImpl configService;

    /**
     * 增加公告
     */
    @RequestMapping(value = "addDialog", method = RequestMethod.GET)
    public JsonResult<Void> addDialog(String title, String content) {
        JsonResult<Void> result = new JsonResult<>();
        configService.addDialogInfo(title, content);
        result.setEnum(ResultEnum.CR_200);
        return result;
    }

    /**
     * 获取最新公告
     */
    @RequestMapping(value = "dialog", method = RequestMethod.GET)
    public JsonResult<DialogEntity> getLastDialog() {
        JsonResult<DialogEntity> result = new JsonResult<>();
        DialogEntity lastDialogInfo = configService.getLastDialogInfo();
        result.setEnum(ResultEnum.CR_200);
        result.setData(lastDialogInfo);
        return result;
    }
}
